package com.zhangyang.esper.epl;

import com.espertech.esper.client.*;
import com.espertech.esper.client.scopetest.SupportUpdateListener;
import com.espertech.esper.client.time.CurrentTimeEvent;
import com.espertech.esper.common.internal.support.SupportBean;
import com.espertech.esper.metrics.instrumentation.InstrumentationHelper;
import com.zhangyang.esper.SupportConfigFactory;
import com.zhangyang.esper.support.bean.SupportBean_S5;
import com.zhangyang.esper.support.bean.SupportMarketDataBean;
import junit.framework.TestCase;


import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Dell
 * @Title:
 * @Description: 请写注释类
 * @date 2022/11/9
 */
public class TestMapEPL extends TestCase {
    private EPServiceProvider epService;




    public void testEPL() {
        String stmtTextConsumer = "select * from java.util.Map where  dst_port='445' ";

        EPStatement stmtConsumer = epService.getEPAdministrator().createEPL(stmtTextConsumer);
        SupportUpdateListener testListener = new SupportUpdateListener();
        stmtConsumer.addListener(testListener);

        Map<String, Object> fieldData = new HashMap();
        fieldData.put("dst_port", "445");
        fieldData.put("received_date", new Date());
        EPRuntime runtime = epService.getEPRuntime();
        runtime.sendEvent(fieldData);
        List<EventBean[]> newDataList = testListener.getNewDataList();
        boolean invoked = testListener.isInvoked();
        EventBean[] andResetLastNewData = testListener.getAndResetLastNewData();
    }

    // helper method to create a Map event with unknown field types
    public void testMapDate() {

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("dst_port", String.class);
        map.put("received_date", Date.class);
        Configuration config = new Configuration();
        config.getEngineDefaults().getLogging().setEnableQueryPlan(true);
        config.getEngineDefaults().getThreading().setInternalTimerEnabled(false);

        config.addEventType("D", map);
        epService = EPServiceProviderManager.getDefaultProvider(config);
        epService.initialize();
        if (InstrumentationHelper.ENABLED) {
            InstrumentationHelper.startTest(epService, this.getClass(), getName());
        }
        String stmtText = " select * from D where  dst_port='445' AND received_date.getTime()>1680074195008";
        EPStatement statement = epService.getEPAdministrator().createEPL(stmtText);
        SupportUpdateListener listener = new SupportUpdateListener();
        statement.addListener(listener);
        Map<String, Object> fieldData = new HashMap();
        fieldData.put("dst_port", "445");
        fieldData.put("received_date", new Date(1680074195009l));
        epService.getEPRuntime().sendEvent(new CurrentTimeEvent(0));
        epService.getEPRuntime().sendEvent(fieldData,"D");
        assertTrue(listener.isInvoked());
    }


    public static void main(String[] args) {
        Map<String, Object> map = new HashMap<>();
        map.put("1","34");

    }

}
